﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace COSIX
{
    static class KernelExtensions
    {
        private static void RebootACPI()
        {
            byte good = 0x02;
            while ((good & 0x02) != 0)
                good = Inb(0x64);
            Outb(0x64, 0xFE);
            Cosmos.Core.Global.CPU.Halt();
            Cosmos.Core.Global.CPU.Halt();
        }

        static Cosmos.Core.IOPort io = new Cosmos.Core.IOPort(0);
        static int PP = 0, D = 0;
        private static void Outb(ushort port, byte data)
        {
            if (io.Port != port)
                io = new Cosmos.Core.IOPort(port);
            io.Byte = data;
            PP = port;
            D = data;

        }
        private static byte Inb(ushort port)
        {
            if (io.Port != port)
                io = new Cosmos.Core.IOPort(port);
            return io.Byte;

        }

        public static void Reboot(this Kernel kernel)
        {
            RebootACPI();
        }

        public static void Shutdown(this Kernel kernel)
        {
            Core.ACPI.Shutdown();
        }
    }
}
